import 'package:flutter/material.dart';
import 'package:get/get.dart';

class ObxPage extends GetView {
  final count = 0.obs;

  @override
  Widget build(BuildContext context) {


    return Scaffold(
      appBar: AppBar(title: Text('ObxPage')),

      body: SafeArea(
        child: ListView(
          children: [
            Text(
              '- Obx 回调函数中的变量会自动更新',
              style: Theme.of(context).textTheme.headline5
            ),
            Divider(),
            // 在 Obx 回调函数中的内容，才能实时更新
            Obx(() => Text(
              'count: '+count.toString(),
              style: Theme.of(context).textTheme.headline4
            )),
            Text(
              'count: '+count.toString(),
              style: Theme.of(context).textTheme.headline4
            ),
            ElevatedButton(
              onPressed: () {
                count.value++;
              }, 
              child: Icon(Icons.add)
            )
          ],
        )
      )
    );
  }
}